<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Capacitor OpenHarmony</title>
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            margin: 0;
            padding: 20px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
        }
        
        .container {
            text-align: center;
            max-width: 400px;
            padding: 30px;
            background: rgba(255, 255, 255, 0.1);
            border-radius: 20px;
            backdrop-filter: blur(10px);
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
        }
        
        .logo {
            font-size: 80px;
            margin-bottom: 20px;
        }
        
        h1 {
            font-size: 2.5em;
            margin: 0 0 10px 0;
            font-weight: 300;
        }
        
        .subtitle {
            font-size: 1.2em;
            margin-bottom: 30px;
            opacity: 0.9;
        }
        
        .button {
            background: rgba(255, 255, 255, 0.2);
            border: 1px solid rgba(255, 255, 255, 0.3);
            color: white;
            padding: 12px 24px;
            margin: 8px;
            border-radius: 25px;
            cursor: pointer;
            font-size: 16px;
            transition: all 0.3s ease;
            display: inline-block;
            min-width: 120px;
        }
        
        .button:hover {
            background: rgba(255, 255, 255, 0.3);
            transform: translateY(-2px);
        }
        
        .info {
            margin-top: 30px;
            padding: 20px;
            background: rgba(0, 0, 0, 0.2);
            border-radius: 10px;
            font-size: 14px;
            text-align: left;
        }
        
        .status {
            margin: 10px 0;
            padding: 10px;
            border-radius: 5px;
            background: rgba(255, 255, 255, 0.1);
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="logo">⚡</div>
        <h1>Capacitor</h1>
        <div class="subtitle">OpenHarmony Application</div>
        
        <button class="button" onclick="testAppInfo()">App Info</button>
        <button class="button" onclick="testAppState()">App State</button>
        <button class="button" onclick="testHttpRequest()">HTTP Test</button>
        <button class="button" onclick="testBackButton()">Back Button</button>
        
        <div class="info">
            <div><strong>Platform:</strong> <span id="platform">Loading...</span></div>
            <div><strong>Status:</strong> <span id="status">Initializing...</span></div>
            <div id="results"></div>
        </div>
    </div>

    <script>
        // Wait for Capacitor to be ready
        document.addEventListener('DOMContentLoaded', function() {
            setTimeout(initializeApp, 500);
        });

        function initializeApp() {
            if (window.Capacitor) {
                document.getElementById('platform').textContent = window.Capacitor.platform || 'Unknown';
                document.getElementById('status').textContent = 'Ready';
                console.log('Capacitor is ready!', window.Capacitor);
            } else {
                document.getElementById('status').textContent = 'Capacitor not available';
                setTimeout(initializeApp, 1000);
            }
        }

        function addResult(title, data) {
            const results = document.getElementById('results');
            const div = document.createElement('div');
            div.className = 'status';
            div.innerHTML = `<strong>${title}:</strong><br><pre>${JSON.stringify(data, null, 2)}</pre>`;
            results.appendChild(div);
        }

        async function testAppInfo() {
            try {
                if (window.Capacitor && window.Capacitor.Plugins.App) {
                    const info = await window.Capacitor.Plugins.App.getInfo();
                    addResult('App Info', info);
                } else {
                    addResult('App Info', { error: 'App plugin not available' });
                }
            } catch (error) {
                addResult('App Info Error', error);
            }
        }

        async function testAppState() {
            try {
                if (window.Capacitor && window.Capacitor.Plugins.App) {
                    const state = await window.Capacitor.Plugins.App.getState();
                    addResult('App State', state);
                } else {
                    addResult('App State', { error: 'App plugin not available' });
                }
            } catch (error) {
                addResult('App State Error', error);
            }
        }

        async function testHttpRequest() {
            try {
                if (window.Capacitor && window.Capacitor.Plugins.CapacitorHttp) {
                    const response = await window.Capacitor.Plugins.CapacitorHttp.get({
                        url: 'https://jsonplaceholder.typicode.com/posts/1'
                    });
                    addResult('HTTP Response', response);
                } else {
                    addResult('HTTP Test', { error: 'HTTP plugin not available' });
                }
            } catch (error) {
                addResult('HTTP Error', error);
            }
        }

        function testBackButton() {
            try {
                if (window.Capacitor && window.Capacitor.Plugins.App) {
                    window.Capacitor.Plugins.App.addListener('backButton', (data) => {
                        addResult('Back Button Pressed', data);
                        console.log('Back button pressed!', data);
                    });
                    addResult('Back Button', { message: 'Listener added. Press device back button to test.' });
                } else {
                    addResult('Back Button', { error: 'App plugin not available' });
                }
            } catch (error) {
                addResult('Back Button Error', error);
            }
        }

        // Log all Capacitor events
        window.addEventListener('capacitor:ready', () => {
            console.log('Capacitor ready event fired');
        });
    </script>
</body>
</html>